<template>
	<view class="bg">
		<view class="tx">
			<image src="../../static/nclogo.png" mode=""></image>
		</view>
		<view class="title">
			用户授权登录
		</view>
		<view class="btn juedui" style="margin: 50rpx auto;">
			<u-button text="立即登录" @click="loginClick()" shape="circle"
				color="linear-gradient(to right, #3AA3FF,#005DFF)"></u-button>
		</view>
<!-- 		<view class="xieyi">
			<u-checkbox-group v-model="checkboxValue1" activeColor="#005DFF" iconSize="36" size="36" placement="column"
				@change="checkboxChange">
				<u-checkbox>
				</u-checkbox>
			</u-checkbox-group>
			<view class="">
				手机号验证成功后并参与兑换即代表您已同意
				<text class="yonghu" @click="xieyi">用户协议</text>
			</view>

		</view> -->

	</view>
</template>

<script>
	import {
		login
	} from '@/api/url.js'
	export default {
		data() {
			return {
				checkboxValue1: true,
				form: {
					username: '',
					password: ''
				},
				cheboxval: true
			}
		},
		onLoad(option) {

		},

		methods: {
			checkboxChange(e) {
				console.log('change', e.length);
				var that = this
				if (e.length == 1) {
					that.cheboxval = true
				} else {
					that.cheboxval = false
				}
			},
			change(e) {
				console.log('change', e);
				this.form.username = e
			},
			changepass(e) {
				console.log('change', e);
				this.form.password = e
			},
			xieyi() {
				uni.navigateTo({
					url: '/pages/login/agree'
				})
			},
			loginClick() {
				var that = this
				console.log(that.form, '入参')
				if (that.cheboxval) {
					uni.showLoading({
						title: '加载中'
					});

					uni.getUserInfo({
						desc: '登录的数据',
						success(ures) {
							console.log(ures, '返回的用户信息');
							//这个地方的用户信息无论登录成功失败都可以拿到，只是拿到用户的信息
							//在成功的回调中去使用微信登录
							uni.login({
								provider: 'weixin', //使用微信登录
								success(lres) {
									console.log(lres, '请求微信登录返回的数据');
									//我们要根据上面获取的code码去作为请求参数发送给后端
									let params = {
										jscode: lres.code
									};
									login(params).then(res => {
										console.log(res)
										uni.hideLoading()
										if (res.data.code == 200) {
											uni.setStorageSync('token', res.data.msg)
											uni.showToast({
												title: '登录成功~',
												icon: 'none',
												duration: 2000
											})
											setTimeout(function() {
												uni.redirectTo({
													url: '/pages/index/index'
												})
											}, 1000)

										} else {
											uni.showToast({
												title: res.data.msg,
												icon: 'none',
												duration: 2000
											})
										}
									})
								}
							});
						}
					});
				} else {
					uni.showToast({
						title: '请勾选用户协议书进行登录~',
						icon: 'none',
						duration: 2000
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	page {}

	.bg {
		width: 100%;

		.tx {
			text-align: center;
			padding: 122rpx 0 60rpx 0;
			box-sizing: border-box;

			image {
				width: 300rpx;
				height: 300rpx;
			}
		}

		.put {
			width: 90%;
			margin: 0 auto;
		}

		.xieyi {
			width: 90%;
			margin: 0 auto;
			margin-top: 49rpx;
			margin-bottom: 80rpx;
			display: flex;
			color: #858BA3;
			font-size: 30rpx;

			.yonghu {
				color: #005DFF;
				text-decoration: underline;
			}
		}

		.title {
			width: 80%;
			margin: 0 auto;
			text-align: center;
			font-size: 30rpx;
			font-weight: 600;
		}

		.wangji {
			display: flex;
			align-items: center;
			justify-content: flex-end;
			width: 90%;
			margin: 0 auto;
			color: #F5C7A6;
			font-size: 30rpx;
			margin-top: 32rpx;

			image {
				width: 36rpx;
				height: 36rpx;
				margin-right: 16rpx;
			}
		}
	}

	input {
		border: 2rpx solid #F5C7A6;
		border-radius: 50rpx;
		padding: 14rpx 48rpx;
	}
</style>